﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:atom="http://www.w3.org/2005/Atom"
    xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices"
    xmlns:ext="urn:Extensions"
    exclude-result-prefixes="msxsl">

  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

  <xsl:param name="detailUri" />
  
  <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
  <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

  <xsl:template match="/">
    <xsl:apply-templates select="//atom:entry">
      <xsl:sort select="ext:FormatDate(./atom:updated, 'yyyyMMddHHmm')" data-type="number" order="descending"/>
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="atom:entry">
    <xsl:if test="position()&gt;1">
      <xsl:element name="div">
        <xsl:attribute name="class">archive-separator</xsl:attribute>
        <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
      </xsl:element>
    </xsl:if>
    <xsl:element name="div">
      <xsl:attribute name="class">post</xsl:attribute>
      <xsl:element name="div">
        <xsl:attribute name="class">archive-post-date</xsl:attribute>
        <xsl:element name="div">
          <xsl:attribute name="class">archive-post-day</xsl:attribute>
          <xsl:value-of select="ext:FormatDate(./atom:updated, 'dd')" />
        </xsl:element>
        <xsl:element name="div">
          <xsl:attribute name="class">archive-post-month</xsl:attribute>
          <xsl:value-of select="translate(substring(ext:FormatDate(./atom:updated, 'MMM'),1,3), $smallcase, $uppercase)" />
        </xsl:element>
      </xsl:element>
      <xsl:element name="div">
        <xsl:attribute name="class">archive-post-title</xsl:attribute>
        <xsl:element name="h3">
          <xsl:element name="a">
            <xsl:attribute name="href">
              <xsl:value-of select="concat($detailUri, ext:GetPackageId(./atom:id), '/', ext:GetPackageVersion(./atom:id))"/>
            </xsl:attribute>
            <xsl:value-of select="./atom:title"/> (<xsl:value-of select="./*/data:Version"/>)
          </xsl:element>
        </xsl:element>
        <xsl:element name="div">
          <xsl:attribute name="class">post-date</xsl:attribute>
          <xsl:value-of select="ext:FormatDate(./atom:updated, 'HH:mm, dddd, MMM dd, yyyy')" />
        </xsl:element>
      </xsl:element>
      <xsl:element name="div">
        <xsl:attribute name="class">clearer</xsl:attribute>
        <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
      </xsl:element>
    </xsl:element>
  </xsl:template>

</xsl:stylesheet>
